package com.zkca.xf.presenter;

import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.ActivityEvent;
import com.zkca.xf.base.BasePresenter;
import com.zkca.xf.manager.DataManager;
import com.zkca.xf.model.javabean.FireAlarmBean;
import com.zkca.xf.model.javabean.UserId;
import com.zkca.xf.view.FireAlarmView;

import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.observers.DefaultObserver;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by pc on 2018/8/21.
 */

public class FireAlarmPresenter extends BasePresenter {
    private DataManager dataManager;
    private FireAlarmView fireAlarmView;

    public FireAlarmPresenter(LifecycleProvider<ActivityEvent> provider,FireAlarmView fireAlarmView) {
        super(provider);
        this.fireAlarmView=fireAlarmView;
        dataManager=DataManager.getInstance();
    }


    public void GetFireAlarm(Map<String, String> map) {
        dataManager.getFireAlarm(map)
                .subscribeOn(Schedulers.io())// 在子线程中进行Http访问
                .observeOn(AndroidSchedulers.mainThread())// UI线程处理返回接口
                .compose(getProvider().<FireAlarmBean>bindUntilEvent(ActivityEvent.DESTROY))// onDestroy取消订阅
                .subscribe(new DefaultObserver<FireAlarmBean>() {// 订阅
                    @Override
                    public void onNext(FireAlarmBean data) {
                        fireAlarmView.getFireAlarm(data);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fireAlarmView.showError(e.getMessage());
                    }

                    @Override
                    public void onComplete() {
                        fireAlarmView.hideProgressDialog();
                    }
                });
    }

}
